package com.zxt.content.common.utils;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;

/**
 * @author zxt
 */
@Deprecated
public class LocalDateTimeUtil {

    /**
     * 将时间转换成 yyyy-MM-dd HH:mm:ss 格式的字符串
     *
     * @return
     */
    public String toFormatString(LocalDateTime time) {
        return time.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }

    public static String format(LocalDate date) {
        return date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    }

    /**
     * 获取一天最早时间
     *
     * @return
     */
    public static LocalDateTime getEarliestOfDay() {
        return LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
    }

    /**
     * 获取一天最晚时间
     *
     * @return
     */
    public static LocalDateTime getLatestOfDay() {
        return LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
    }

    /**
     * 获取周最早时间
     *
     * @return
     */
    public static LocalDateTime getEarliestOfWeek() {
        return getEarliestOfDay().with(DayOfWeek.MONDAY);
    }

    /**
     * 获取周最晚时间
     *
     * @return
     */
    public static LocalDateTime getLatestOfWeek() {
        return getLatestOfDay().with(DayOfWeek.SUNDAY);
    }

    /**
     * 获取月最早时间
     *
     * @return
     */
    public static LocalDateTime getEarliestOfMonth() {
        return getEarliestOfDay().with(TemporalAdjusters.firstDayOfMonth());
    }

    /**
     * 获取月最晚时间
     *
     * @return
     */
    public static LocalDateTime getLatestOfMonth() {
        return getLatestOfDay().with(TemporalAdjusters.lastDayOfMonth());
    }

    /**
     * 获取今年最早时间
     *
     * @return
     */
    public static LocalDateTime getEarliestOfYear() {
        return getEarliestOfDay().with(TemporalAdjusters.firstDayOfYear());
    }

    /**
     * 获取今年最晚时间
     *
     * @return
     */
    public static LocalDateTime getLatestOfYear() {
        return getLatestOfDay().with(TemporalAdjusters.lastDayOfYear());
    }

}
